package interaction.input.concrete;

import processing.core.PVector;
import interaction.ServiceLocator;
import interaction.input.DataComponent;
import interaction.sampling.Sample;
import interaction.sampling.SampleSet;
import interaction.sampling.matching.Matcher;

public abstract class AbstractBeatComponent<T> extends DataComponent<T>{

	public AbstractBeatComponent(PVector position, PVector size) {
		super(position, size);
	}
	
	public Matcher getMatcher()
	{
		return ServiceLocator.getSampleMatcher();
	}
	
	public SampleSet getTapSamples()
	{
		return ServiceLocator.getTapSamples();
	}
	
	public SampleSet getSlapSamples()
	{
		return ServiceLocator.getSlapSamples();
	}
	
	public void beatReceived(Sample beat) {
		Matcher signatureMatcher = getMatcher();
		SampleSet tapSignature = getTapSamples();
		SampleSet slapSignature = getSlapSamples();
		
		double tapRating = signatureMatcher.match(beat, tapSignature);
		double slapRating = signatureMatcher.match(beat, slapSignature);
		double treshold = signatureMatcher.getAcceptanceTreshold();
		
		if ((tapRating >= treshold) && (tapRating > slapRating)) {
			tapReceived(beat);
		} else if ((slapRating >= treshold) && (slapRating > tapRating)) {
			slapReceived(beat);
		}
	}
	
	public void tapReceived(Sample s)
	{
	}
	
	public void slapReceived(Sample s)
	{
	}

}
